package logic

import (
	"api/pkg"
	"context"
	"house_srv/house"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderCreateLogic {
	return &OrderCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderCreateLogic) OrderCreate(req *types.OrderCreateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	create, err := l.svcCtx.HouseSrv.OrderCreate(l.ctx, &house.OrderCreateRequest{
		UserId:  req.UserId,
		HouseId: req.HouseId,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: pkg.Tri(err.Error()),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "订单下单成功",
		Data: map[string]interface{}{
			"UrlType": create.UrlType,
			"OrderId": create.OrderId,
		},
	}, nil
}
